package com.lzp.wechat;

import com.alibaba.fastjson.JSON;
import com.aliyun.chatbot20171011.Client;
import com.aliyun.chatbot20171011.models.ChatRequest;
import com.aliyun.chatbot20171011.models.ChatResponse;
import com.aliyun.teaopenapi.models.Config;

public class Sample {

    /**
     * 使用AK&SK初始化账号Client
     *
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.chatbot20171011.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret
                .setAccessKeySecret(accessKeySecret)
                .setRegionId("cn-shanghai")
                .setEndpoint("ecs-cn-shanghai.aliyuncs.com");
        // 访问的域名
        config.endpoint = "chatbot.cn-shanghai.aliyuncs.com";
        return new Client(config);
    }

    public static void main(String[] args_) throws Exception {
        Client client = Sample.createClient("LTAI5tMxcEsSoeEiRHKg4xYJ", "WdSkxvhNjXZHvM7bpcU1V6lECRT2YN");
        ChatRequest chatRequest = new ChatRequest()
                .setUtterance("你好")
                .setInstanceId("chatbot-cn-I3z7I3jbaa");
        // 复制代码运行请自行打印 API 的返回值
        ChatResponse chatResponse = client.chat(chatRequest);
        System.out.println(JSON.toJSONString(chatResponse));
    }
}